package hn.sigit.view.workflow.transaction;

import hn.sigit.model.commons.IResponsibility;
import hn.sigit.model.hnd.ladmshadow.Responsibility;
import hn.sigit.model.ladm.administrative.LA_ResponsibilityType;
import hn.sigit.model.ladm.external.ExtParty;
import hn.sigit.view.ShareValue;

public class ParcelResponsibility extends ParcelRRR {
	private LA_ResponsibilityType rrrType;
	
	public ParcelResponsibility(long presentationId, ExtParty extParty) {
		super(presentationId, extParty);
		this.rrr = Responsibility.newResponsibility(0, presentationId, false, false);
	}
	public ParcelResponsibility(long presentationId, ExtParty extParty, ShareValue share, IResponsibility responsibility) {
		super(presentationId, extParty, share);
		this.rrr = responsibility;
	}
	
	@Override
	public LA_ResponsibilityType getRrrType() {
		return rrrType;
	}
	public void setRrrType(LA_ResponsibilityType rrrType) {
		if (this.rrrType != rrrType) {
			this.rrrType = rrrType;
			setModified(true);
		}
	}
	//this is to make it work on Mac OS X servers
	public void setRrrType(Object rrrType) {
		setRrrType((LA_ResponsibilityType) rrrType);
	}
	
	@Override
	public String getTypeString() {
		if (rrrType == null) return "";
		
		return rrrType.name();
	}
	
	
	public void cancelChanges() {
		if (rrr == null) return;
		
		super.cancelChanges();
		this.rrrType = (LA_ResponsibilityType) ((IResponsibility) rrr).getType();
	}
	
	protected void applyChanges() {
		if (rrr == null) return;
		
		super.applyChanges();
		((Responsibility) rrr).setType((LA_ResponsibilityType)rrrType);
	}
}
